package com.wchat.repository;

import com.wchat.dataobject.MyMessage;
import com.wchat.dto.MyMessageDTO;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * Created by yangtianrui on 18/7/26.
 */
@Repository
public interface MyMessageRepository extends JpaRepository<MyMessage,Integer> {

//    @Query(value = "select new com.wchat.dto.MyMessageDTO(m.userId,u.cuteName,m.messageContent,m.unReadNum,m.date,u.headImage) FROM MyMessage m LEFT JOIN  UserEntity u  ON u.userId=m.fromUserId where m.userId = ? 1")
//    List<MyMessageDTO> findMyMessageList(Integer userId);
    @Query(value = "select * from my_message where user_id = ?1",nativeQuery = true)
    List<MyMessage> findByUserId(Integer userId);

    @Query(value = "select  COUNT(*) from my_message where from_user_id = ?1 ",nativeQuery = true)
    int getUnReadMessageCount(Integer userId);

    @Query(value = "INSERT INTO `my_message` ( `user_id`, `from_user_id`, `message_content`, `un_read_num`, `date`)VALUES ( 123, 12, '爱呀 呃呃呃呃呃', 1, '2018-08-15 13:55:33');",nativeQuery = true)
    int inserMymessage(String userId,String fromUserId,String messageContent,Integer unReadNum,Date date);
}






